package com.ghck.server.service.impl;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ghck.server.dao.RoleMapper;
import com.ghck.server.model.Role;
import com.ghck.server.model.query.RoleQuery;
import com.ghck.server.service.RoleService;

/**
 * 角色表  <br>
 * t_role <br>
 * v1.0 2016-05-01
 */
 @Service
 @Transactional
 public class RoleServiceImpl implements RoleService {
	private static final Logger logger = LoggerFactory.getLogger(RoleService.class);
	
	@Autowired
	private RoleMapper roleMapper;
	
	/**
 	*根据ID删除 角色表
 	*/
 	@Override
 	public Integer deleteRoleById(Integer id){
 		return roleMapper.deleteById(id);
 	}
 	
 	/**
 	*新增 角色表
 	*/
 	@Override
 	@Transactional
 	public Integer batchInsertRole(List<? extends Role> roles){
		Integer count = roleMapper.batchInsert(roles);
		return count;
 	}
 	/**
 	*新增 角色表
 	*/
 	@Override
 	@Transactional
 	public Integer insertRole(Role domain){
		Integer id = roleMapper.insert(domain);
		return id;
 	}

 	/**
 	*更新 角色表
 	*/
 	@Override
 	@Transactional
 	public Integer updateRole(Role domain){
		Integer count = roleMapper.update(domain);
		return count;
 	}
 	
 	/**
 	*根据ID查询 角色表
 	*/
 	public Role findRoleById(Integer id){
 		Role result = roleMapper.findById(id);
 		if(result!=null){
 			result.dealWith();
 		}
 		return result;
 	}

	/**
 	*通过query 查询 角色表
 	*/
	public List<Role> findRoleByQuery(RoleQuery query){
		query.dealWith();
		List<Role> result = roleMapper.findByQuery(query);
		if(CollectionUtils.isNotEmpty(result)) {
			for (Role role : result) {
				role.dealWith();
			}
		}
		return result;
	}	
	
	/**
 	*通过query count总条数
 	*/
 	public Integer countRoleByQuery(RoleQuery query){
 		query.dealWith();
 		Integer result = roleMapper.countByQuery(query);
 		return result;
 	}
 	
 	/**
 	* 通过ids查询
 	*/
 	public List<Role> findRoleByIds(List<Integer> ids){
 		List<Role> result = roleMapper.findByIds(ids);
		if(CollectionUtils.isNotEmpty(result)) {
			for (Role role : result) {
				role.dealWith();
			}
		}
		return result;
 	}
 	
}	